package com.ai.bitcoin.jpa.service.impl;

import com.ai.bitcoin.jpa.dao.BccRankDao;
import com.ai.bitcoin.jpa.entity.BccRank;
import com.ai.bitcoin.jpa.service.BccRankService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author Jason
 * @date 2018/3/29
 **/
@Service
public class BccRankServiceImpl implements BccRankService {
    @Autowired
    BccRankDao dao;

    @Override
    public BccRank findByBccIdAndRecordState(String bccId, String recordState) {
        List<BccRank> list = dao.findByBccIdAndRecordState(bccId, recordState);
        if (list.size() == 1)
            return list.get(0);
        return null;
    }

    @Override
    @Transactional
    public BccRank save(BccRank bccRank) {
        return dao.save(bccRank);
    }

    @Override
    public List<BccRank> findByRecordState(String recordState) {
        return dao.findByRecordStateOrderByValueScoreDesc(recordState);
    }

    @Override
    @Transactional
    public void updateRank(String unPublishBatch) {
        dao.deleteOldBatch(unPublishBatch);
        dao.updateNewBatch2Publish(unPublishBatch);
    }

    @Override
    public List<BccRank> findByBatchNo(String batch) {
        return dao.findByBatchNo(batch);
    }

    @Override
    public Page<BccRank> findByRecordState(String recordState, Pageable pageable) {
        return dao.findByRecordState(recordState, pageable);
    }

    @Override
    @Transactional
    public void deleteNoPublish() {
        dao.deleteNoPublish();
    }

    @Override
    public List<BccRank> findByBatchNoAndRecordStateOrderByValueScoreDesc(String batch, String recordState) {
        return dao.findByBatchNoAndRecordStateOrderByValueScoreDesc(batch, recordState);
    }

    @Override
    public List<BccRank> findByBatchNoAndRecordStateOrderByPotentialScoreDesc(String batch, String recordState) {
        return dao.findByBatchNoAndRecordStateOrderByPotentialScoreDesc(batch, recordState);
    }

    @Override
    public List<BccRank> findByBatchNoAndRecordState(String batch, String recordState) {
        return dao.findByBatchNoAndRecordState(batch, recordState);
    }

    @Override
    public List<BccRank> findByBatchNoAndRecordStateOrderByValueUpPercentDesc(String batch, String recordState) {
        return dao.findByBatchNoAndRecordStateOrderByValueUpPercentDesc(batch, recordState);
    }

    @Override
    public List<BccRank> findByBatchNoAndRecordStateOrderByPotentialUpPercentDesc(String batch, String recordState) {
        return dao.findByBatchNoAndRecordStateOrderByPotentialUpPercentDesc(batch, recordState);
    }

    @Override
    public List<BccRank> findByBatchNoAndRecordStateOrderBySupplyScoreDesc(String batch, String recordState) {
        return dao.findByBatchNoAndRecordStateOrderBySupplyScoreDesc(batch, recordState);
    }

    @Override
    public List<BccRank> findByBatchNoAndRecordStateOrderByNeedScoreDesc(String batch, String recordState) {
        return dao.findByBatchNoAndRecordStateOrderByNeedScoreDesc(batch, recordState);
    }

    @Override
    public List<BccRank> findByBatchNoAndRecordStateOrderByInnerScoreDesc(String batch, String recordState) {
        return dao.findByBatchNoAndRecordStateOrderByInnerScoreDesc(batch, recordState);
    }

    @Override
    public List<BccRank> findByBatchNoAndRecordStateOrderByMoodScoreDesc(String batch, String recordState) {
        return dao.findByBatchNoAndRecordStateOrderByMoodScoreDesc(batch, recordState);
    }

    @Override
    public List<BccRank> findByBatchNoAndRecordStateOrderBySafeScoreDesc(String batch, String recordState) {
        return dao.findByBatchNoAndRecordStateOrderBySafeScoreDesc(batch, recordState);
    }

    @Override
    public List<BccRank> findByBatchNoAndRecordStateOrderByFutureScoreDesc(String batch, String recordState) {
        return dao.findByBatchNoAndRecordStateOrderByFutureScoreDesc(batch, recordState);
    }

    @Override
    public List<BccRank> findByBatchNoAndRecordStateOrderByGasScoreAsc(String batch, String recordState) {
        return dao.findByBatchNoAndRecordStateOrderByGasScoreAsc(batch, recordState);
    }
}
